using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Musicman.Entities;
using Musicman.Business;

namespace MusicmanWeb.USER
{
    public partial class Helpdesk : MusicmanPage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            ReddirectNonActiveSession();
        }

        protected void LinkButton1_Command(object sender, CommandEventArgs e)
        {
            Userfeedback ufb = new Userfeedback();
            ufb.Personid = (long)Session["UserID"];
            ufb.Subject = this.Subject.Text;
            ufb.Feedback = this.Feedback.Text;
            ufb.Date = DateTime.Now;
            DataManager.Instance.InserUserFeedBack(ufb);
            GridView1.DataBind();
            GridView2.DataBind();
            GridView2.Visible = true;
            GridView3.Visible = false;
            this.Subject.Text = "";
            this.Feedback.Text = "";
        }


        protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex != -1)
            {
                string loggedUser = (Session["UserID"] == null) ? "" : Session["UserID"].ToString();
                string userID = ((System.Web.UI.WebControls.HiddenField)e.Row.Cells[0].FindControl("UserID")).Value;
                if (!User.IsInRole("ADMIN") && (loggedUser != userID))
                {
                    e.Row.Cells[1].FindControl("Edit").Visible = false;
                    e.Row.Cells[1].FindControl("Delete").Visible = false;
                }
            }
        }

        protected void Search_Command(object sender, CommandEventArgs e)
        {
            this.ObjectDataSource3.SelectParameters[0].DefaultValue = e.CommandArgument.ToString();
            this.GridView2.Visible = false;
            this.GridView3.DataBind();
            this.GridView3.Visible = true;
        }

        protected void GridView3_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {
            GridView1.DataBind();
        }

    }

}
